package com.zmc.lostfound.post.controller;

import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.post.entity.PostReviewEntity;
import com.zmc.lostfound.post.service.PostReviewService;
import com.zmc.lostfound.post.vo.PostReviewQueryVO;
import com.zmc.lostfound.post.vo.PostReviewSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author WJS
 * @description 审核信息管理接口
 * @email 2869581855@qq.com
 * @date 2023-07-05 15:49:44
 */
@RestController
@RequestMapping("/postReview")
@Api(value = "审核信息管理接口", tags = "审核信息管理接口")
public class PostReviewController {

    private final PostReviewService postReviewService;

    public PostReviewController(PostReviewService postReviewService) {
        this.postReviewService = postReviewService;
    }

    @ApiOperation("多条件查询审核信息")
    @GetMapping("/query/page")
    public Result queryPage(@Validated PostReviewQueryVO postReviewQueryVO) {
        return Result.ok("查询成功").put("pageResult", postReviewService.queryPage(postReviewQueryVO));
    }

    @ApiOperation("按id查询审核信息")
    @GetMapping("/query/infoById/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        PostReviewEntity postReviewInfo = postReviewService.queryInfoById(id);
        return Result.ok("查询成功").put("postReviewInfo", postReviewInfo);
    }

    @ApiOperation("新增审核信息")
    @PostMapping("/insertPostReview")
    public Result insertPostReview(@RequestBody @Validated(value = {AddGroup.class}) PostReviewSaveVO postReviewSaveVO) {
        return postReviewService.insertPostReview(postReviewSaveVO);
    }

    @ApiOperation("修改审核信息")
    @PutMapping("/updatePostReview")
    public Result updatePostReview(@RequestBody @Validated(value = {UpdateGroup.class}) PostReviewSaveVO postReviewSaveVO) {
        return postReviewService.updatePostReview(postReviewSaveVO);
    }

    @ApiOperation("按主键id删除审核信息")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        return postReviewService.deleteById(id);
    }

    @ApiOperation("按帖子id批量删除审核信息")
    @DeleteMapping("/deleteBatchByPostId/{postId}")
    public Result deleteBatchByPostId(@PathVariable("postId") Long postId) {
        return postReviewService.deleteBatchByPostId(postId);
    }

}
